package com.rmv.ums.condition;

import javax.servlet.http.HttpServletRequest;

import org.apache.log4j.Logger;
import org.dom4j.Element;

public class ParameterRegExCondition extends RegExCondition{
	
	private static final Logger logger = Logger.getLogger(ParameterRegExCondition.class);
	
	private String param;

	public String getParam() {
		return param;
	}

	public void setParam(String param) {
		this.param = param;
	}
	

	public String getValueToCheck(HttpServletRequest request) {
		String paramKey = getParam();
		String paramValue = request.getParameter(paramKey);
		if (logger.isDebugEnabled())
			logger.debug("value(parameter) to check on regex condition: key=" + paramKey+",value="+paramValue);
		return paramValue; 
	}
	
	public boolean configure(Element element) {
		if(!super.configure(element)) return false;

		//param
		this.param = element.attribute("param").getStringValue();
		
		return true;
	}
	
	public String toString() {
		return "[condition:type="+type+",parameter="+param+",value="+value+"]";
	}

}
